import React from 'react';
import {Button, Linking, Text, View} from 'react-native';
import {useAsyncStorage} from '@react-native-async-storage/async-storage';

const MyInfo = () => {
  const asyncStorage = useAsyncStorage('favorite');

  const handleClearCache = async () => {
    try {
      await asyncStorage.removeItem();
      console.log('删除成功');
    } catch (error) {
      console.log(error);
    }
  };

  const getCacheData = async () => {
    try {
      const res = await asyncStorage.getItem();
      console.log(JSON.parse(res!));
    } catch (error) {
      console.log(error);
    }
  };

  const tel = async () => {
    const supported = await Linking.canOpenURL('tel:18267103711');
    if (supported) {
      await Linking.openURL('tel:18267103711');
    } else {
      console.log('暂不支持～');
    }
  };

  return (
    <View>
      <Button title="清除缓存" onPress={handleClearCache} />
      <Button title="获取缓存" onPress={getCacheData} />
      <Button title="拨打电话" onPress={tel} />
    </View>
  );
};

export default MyInfo;
